<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/8/17
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery.js"></script>
</head>
<body>
    <form id="form" action="AddServlet">
        <table border="1">
            <tr>
                <th colspan="2"><h2>添加组织机构信息</h2></th>
            </tr>
            <tr>
                <td>组织机构名称(*)</td>
                <td><input type="text" id="name" name="name"> <span class="spanName"></span></td>
            </tr>
            <tr>
                <td>负责人(*)</td>
                <td><input type="text" id="principalName" name="principalName"></td>
            </tr>
            <tr>
                <td>创建日期(*)</td>
                <td><input type="text" id="createDate" name="createDate"></td>
            </tr>
            <tr><td colspan="2">
                <input type="button" value="返回" onclick="history.back()">
            </td></tr>
        </table>
        <input type="submit" value="提交">
    </form>
</body>
<script src="js/jquery.js"></script>
<script>
    // $("form").submit(function () {
    //
    // })
    $("#form").submit(function(){
        let veg=/^\d{4}-\d{2}-\d{2}$/;
        if ($('#name').val()==='' ||  $('#principalName').val()==='' ||  $('#createDate').val()===''){
            alert("请填写完整的组织机构信息！");
            return false;
        }else if (!veg.test($('#createDate').val())){
            alert("日期格式不正确！");
            return false;
        }
        var name=$('#name').val();
        $.ajax({
            url:"CheckNameServlet",
            data:"name="+name,
            dataType:"text",
            success:function (data) {
                if (data==="true") {
                    $('.spanName').text("该组织机构已存在");
                    return false;
                }
            }
        })
    })

</script>
</html>
